package thread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

public class SleepDemo {
    public static void main(String[] args) throws IOException {

        Scanner sc=new Scanner(System.in);
        sc.nextInt();
        System.out.println("需要倒计时的秒数:");
        BufferedReader br=new BufferedReader(
                new InputStreamReader( System.in)
        );
        String line=br.readLine();
        int i=Integer.parseInt(line);
        while (i>0){
            try {
                Thread.sleep(1000,1);
                System.out.println(i--);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.println("结束");
        System.out.println("需要倒计时的秒数:");
       // int jk=sc.nextInt();
        Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            private int j=3;
            @Override
            public void run() {
                if(j<1){
                    timer.cancel();
                    this.cancel();
                }

                System.out.println(j--);
            }
        },0,1000);

     //  Thread.currentThread().();

    }
static void g_$dfdf(){

}
}

